<?php

namespace app\admin\model;

use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
use think\facade\Db;

class WebHonorExamples extends BaseModel
{

    use SoftDelete;

    

    // 表名
    protected $name = 'web_honor_examples';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'state_text'
    ];
    
    /**
    * @param Model $row
    */
    protected static function onAfterInsert($row){
        $pk = $row->getPk();
        $row->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
    }

    // 修改展示类型
    public function getStateList()
    {
        $list = Db::name('web_label')->field('id,name')->where('state',2)->select()->toArray();
        $arr = array_column($list, 'name','id');
        return $arr;
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    // 五个区固定选择
    public function address()
    {
        return ['顺德园','禅城园','南海园','高明园','三水园'];
    }




}
